// https://nuxt.com/docs/api/configuration/nuxt-config
const CompressionWebpackPlugin = require('compression-webpack-plugin')
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

export default defineNuxtConfig({
  devtools: { enabled: false },
  ssr: true,

  devServer: {
    port: 9002
  },

  components: true,

  nitro: {
    compressPublicAssets: true,
  },


  experimental: {
    payloadExtraction: true,
    writeEarlyHints: true,
  },

  app: {
    pageTransition: { name: 'page', mode: 'out-in' },
    head: {
      // SEO优化
      title: "Lin | Website",
      charset: 'utf-8',
      meta: [
        {
          charset: 'utf-8'
        },
        { 
          name: "description",
          content: "Website, width=device-width, initial-scale=1.0, user-scalable=yes,shrink-to-fit=no"
        },

        { 
          name: "keyword",
          content: "Lin | Website, width=device-width, initial-scale=1.0, user-scalable=yes,shrink-to-fit=no" 
        },

        { 
          name: 'viewport',
          content: 'width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1, maximum-scale=1, user-scalable=yes' 
        },
        {
           name:"mobile-web-app-capable",
           content: "yes"
        },
        {
          name:"apple-mobile-web-app-status-bar-style",
          content: "black"
        },
        {
          name:"format-detection",
          content: "telephone=no"
        },
      ],

      // 网页图标
      link: [
        { rel: "icon", type: "image/x-icon", href: "/logo.svg" },
        { rel: "stylesheet", type: "text/css", href: "https://unicons.iconscout.com/release/v4.0.8/css/line.css"},
        { rel: "stylesheet", type: "text/css", href: "https://unicons.iconscout.com/release/v4.0.8/script/monochrome/bundle.js"},
        { rel: "stylesheet", type: "text/css", href: "https://unicons.iconscout.com/release/v4.0.8/css/solid.css"},
        { rel: "stylesheet", type: "text/css", href: "https://unicons.iconscout.com/release/v4.0.8/css/thinline.css"},
      ],
    },
    baseURL: process.env.BASE_URL  || '/'
  },


  plugins: [
    // {src: '@/assets/main.js', mode: 'client'},
    {src: '@/plugins/remixicon.js', mode: 'client' },
    {src: '@/plugins/gsap.js', mode: 'client'},
    {src: '@/plugins/element-plus-icons.ts', mode: 'client'},

    // {src: '@/plugins/pixi.client.js', mode: 'client'}
  ],

  css: [
    '~/assets/style.css',
    '~/assets/media.css',
    '~/assets/fonts.css',
    '~/assets/header.css'
  ],

  build : {
    transpile: ["gsap"],
    optimization: {
      minimize: true,
      minimizer: [
        // new CssMinimizerPlugin(),
      ],
      splitChunks: { // 生成 chunk 的最小体积（以 bytes 为单位）
        chunks: "all",
        automaticNameDelimiter: "-",
        maxSize: 102400,
        cacheGroups: {
          vendors: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10, //优先级
            reuseExistingChunk: true,
          },
          common: {
            minChunks: 2,
            priority: -20, //优先级
            reuseExistingChunk: true,
          },
        },
      },
    },

    extend(config: any, { isDev, isClien }) {
      if (!isDev && isClien) {
        config.plugins.push(
          new CompressionWebpackPlugin({
            filename: '[path].gz', 
            algorithm: 'gzip',
            test: /\.(js|css|html|svg)$/,  // 匹配文件名
            threshold: 10240, // 对超过10kb的数据进行压缩
            minRatio: 0.8,
            deleteOriginalAssets: false, // 是否删除原文件
          })
        )
      }
    },
  },

  modules: [
    '@nuxtjs/google-fonts',
     '@element-plus/nuxt',
      "nuxtjs-naive-ui",
    ],

  vite: {
    plugins: [
      AutoImport({
        imports: [
          {
            'naive-ui': [
              'useDialog',
              'useMessage',
              'useNotification',
              'useLoadingBar',
              'n-carousel'
            ]
          }
        ]
      }),
      Components({
        resolvers: [NaiveUiResolver()]
      })
    ]
  },

  googleFonts: {
    families: {
        'Noto Sans SC': [100, 200, 300, 400, 500, 600, 700, 800],  // 中文无衬线字体
        'Noto Serif SC': true , // 中文衬线体
      }
  },



})